package com.xgame.server.dbtool;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xgame.server.db.mapper.AccountrecordMapper;
import com.xgame.server.db.model.Accountrecord;
import com.xgame.server.netty.proto.Game;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class AccountrecordCsTool {
    @Resource
    private AccountrecordMapper accountrecordMapper;

    //插入玩家记录
    public Integer insertAccountRecord(Game.AccountRecordCS data) throws Exception {
        Integer result = new Integer(0);

        Accountrecord account = new Accountrecord();
        account.setAccount(data.getAccount());
        account.setPlayerId(data.getPlayerID());
        account.setDiamondAdd(data.getDiamondAdd());
        account.setDiamondAddVip(data.getDiamondAddVip());
        account.setDiamondUse(data.getDiamondUse());
        account.setDiamondUseVip(data.getDiamondUseVip());
        account.setDiamondDayAdd(data.getDiamondDayAdd());
        account.setDiamondDayAddVip(data.getDiamondDayAddVip());
        account.setDiamondDayUse(data.getDiamondDayUse());
        account.setDiamondDayUseVip(data.getDiamondDayUseVip());

        return accountrecordMapper.insert(account);
    }

    //更新玩家记录
    public Integer updateAccountRecord(Game.AccountRecordCS data) throws Exception {
        EntityWrapper<Accountrecord> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", data.getAccount());

        Accountrecord account = new Accountrecord();
        account.setAccount(data.getAccount());
        account.setPlayerId(data.getPlayerID());
        account.setDiamondAdd(data.getDiamondAdd());
        account.setDiamondAddVip(data.getDiamondAddVip());
        account.setDiamondUse(data.getDiamondUse());
        account.setDiamondUseVip(data.getDiamondUseVip());
        account.setDiamondDayAdd(data.getDiamondDayAdd());
        account.setDiamondDayAddVip(data.getDiamondDayAddVip());
        account.setDiamondDayUse(data.getDiamondDayUse());
        account.setDiamondDayUseVip(data.getDiamondDayUseVip());

        return accountrecordMapper.update(account, userWrapper);
    }

    //删除记录
    public Integer deleteAccountRecord(Game.AccountRecordCS data) throws Exception {
        EntityWrapper<Accountrecord> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", data.getAccount());

        return accountrecordMapper.delete(userWrapper);
    }

    //查询记录
    public List<Accountrecord> selectAccountRecord(String account) throws Exception {
        EntityWrapper<Accountrecord> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return accountrecordMapper.selectList(userWrapper);
    }
}
